﻿using System.Diagnostics;

namespace NExplorer.Core.Commands
{
	internal class VerbCommand : CommandBase
	{
		private readonly string _verb;

		private VerbCommand(string text, string verb)
			: base(text)
		{
			_verb = verb;
		}

		public static ICommand Create(string verb)
		{
			ICommand command;

			switch (verb.ToLower())
			{
				case "open":
					command = new VerbCommand("Open", "open");
					break;

				case "opennew":
					command = new VerbCommand("Open New", "opennew");
					break;

				case "edit":
					command = new VerbCommand("Edit", "edit");
					break;

				case "play":
					command = new VerbCommand("Play", "play");
					break;

				case "print":
					command = new VerbCommand("Print", "print");
					break;

				case "preview":
					command = new VerbCommand("Preview", "preview");
					break;

				case "runas":
					command = new VerbCommand("Run As...", "runas");
					break;

				default:
					command = null;
					break;
			}

			return command;
		}

		protected override void Execute(System.IO.FileSystemInfo fileSystemInfo)
		{
			ProcessStartInfo startInfo = new ProcessStartInfo(fileSystemInfo.FullName);
			startInfo.Verb = _verb;

			try
			{
				Process.Start(startInfo);
			}
			catch 
			{}
		}
	}
}